package com.jewel.service.impl;

import com.jewel.mapper.TabArticleMapper;
import com.jewel.mapper.TabBlockMapper;
import com.jewel.model.Article;
import com.jewel.pojo.TabArticle;
import com.jewel.pojo.TabBlock;
import com.jewel.service.ArticleService;
import com.jewel.tools.Tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 文章模块业务类
 * 
 * @author DELL
 *
 * @since 2017.04.27
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private TabArticleMapper tabArticleMapper;

    @Autowired
    private TabBlockMapper tabBlockMapper;
    

    /**
	 * @Title: getArticleById
	 * @Description：获取指定id文章
	 * 
	 * @param articleId
	 * @return Article
	 * @throws：
	 * 
	 */
    @Override
	public Article getArticleById(int articleId) {
        Article article = null;

        TabArticle tabArticle = this.tabArticleMapper.selectByPrimaryKey(articleId);
        TabBlock tabBlock = this.tabBlockMapper.selectByPrimaryKey(tabArticle.getBlockId());

        if (!Tools.objectIsNullOrNot(tabArticle) && !Tools.objectIsNullOrNot(tabBlock)){
            article = new Article();

            article.setTitle(tabArticle.getTitle());
            article.setText(tabArticle.getText());
            article.setBlockName(tabBlock.getName());
            article.setCommentNumber(tabArticle.getCommentNumber());
            article.setDateAdd(tabArticle.getDateAdd());
        }

        return article;
    }


}
